const express=require('express');
const path=require('path');

const static=require('express-static');
const bodyParser=require('body-parser');
const multer=require('multer');
const multerObj=multer({dest: './static/upload'});
const cookieParser=require('cookie-parser');
const cookieSession=require('cookie-session');
const consolidate=require('consolidate');
const expressRoute=require('express-route');



var server=express();
server.listen(3000);

//设置跨域访问
// server.all('*', function(req, res, next) {
//    res.header("Access-Control-Allow-Origin", "*");
//    res.header("Access-Control-Allow-Headers", "*");
//    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
//    res.header("X-Powered-By",' 3.2.1');
//    res.header("Content-Type", "application/json;charset=utf-8");
//    next();
// });

server.use(bodyParser.urlencoded({extended:false}));
//1.获取请求数据
//get自带
server.use(multerObj.any());

//2.cookie、session
server.use(cookieParser());
(function (){
  var keys=[];
  for(var i=0;i<100000;i++){
    keys[i]='a_'+Math.random();
  }
  server.use(cookieSession({
    name: 'sess_id',
    keys: keys,
    maxAge: 20*60*1000  //20min
  }));
})();

//3.模板/*写接口不需要设置模板*/
 // server.engine('html', consolidate.ejs);
// server.set('views', 'template');
// server.set('view engine', 'html');



//5.route
server.use('/admin/', require('./route/admin_router.js')());
server.use('/', require('./route/index.js')());


//6.default：static
server.use(static('./src/'));
